package com.cspm.gen.enums;

/**
 * 数据库驱动枚举
 * <p>
 * jdbc:odps	com.aliyun.odps.jdbc.OdpsDriver
 * jdbc:derby	org.apache.derby.jdbc.EmbeddedDriver
 * jdbc:mysql	com.mysql.jdbc.Driver
 * jdbc:oracle	oracle.jdbc.driver.OracleDriver
 * jdbc:microsoft	com.microsoft.jdbc.sqlserver.SQLServerDriver
 * jdbc:sybase:Tds	com.sybase.jdbc2.jdbc.SybDriver
 * jdbc:jtds	net.sourceforge.jtds.jdbc.Driver
 * jdbc:postgresql	org.postgresql.Driver
 * jdbc:fake	com.alibaba.druid.mock.MockDriver
 * jdbc:mock	com.alibaba.druid.mock.MockDriver
 * jdbc:hsqldb	org.hsqldb.jdbcDriver
 * jdbc:db2	COM.ibm.db2.jdbc.app.DB2Driver
 * jdbc:sqlite	org.sqlite.JDBC
 * jdbc:ingres	com.ingres.jdbc.IngresDriver
 * jdbc:h2	org.h2.Driver
 * jdbc:mckoi	com.mckoi.JDBCDriver
 * jdbc:cloudscape	COM.cloudscape.core.JDBCDriver
 * jdbc:informix-sqli	com.informix.jdbc.IfxDriver
 * jdbc:timesten	com.timesten.jdbc.TimesTenDriver
 * jdbc:as400	com.ibm.as400.access.AS400JDBCDriver
 * jdbc:sapdb	com.sap.dbtech.jdbc.DriverSapDB
 * jdbc:JSQLConnect	com.jnetdirect.jsql.JSQLDriver
 * jdbc:JTurbo	com.newatlanta.jturbo.driver.Driver
 * jdbc:firebirdsql	org.firebirdsql.jdbc.FBDriver
 * jdbc:interbase	interbase.interclient.Driver
 * jdbc:pointbase	com.pointbase.jdbc.jdbcUniversalDriver
 * jdbc:edbc	ca.edbc.jdbc.EdbcDriver
 * jdbc:mimer:multi1	com.mimer.jdbc.Driver
 * <p>
 * Created by CHQIU on 2017-08-18.
 */

public enum DriverCLassEnum {
    ODPS("odps", "com.aliyun.odps.jdbc.OdpsDriver", "url"),
    DERBY("derby", "org.apache.derby.jdbc.EmbeddedDriver", "url"),
    MYSQL("mysql", "com.mysql.jdbc.Driver", "jdbc:mysql://[server]:[port]/[database]?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8"),
    ORACLE("oracle", "oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@[server]:[port]:[database]"),
    SQLSERVER("sqlserver", "com.microsoft.jdbc.sqlserver.SQLServerDriver", "jdbc:sqlserver://[server]:[port];DatabaseName=[database];integratedSecurity=false"),
    SYBASE("sybase", "com.sybase.jdbc2.jdbc.SybDriver", "jdbc:sybase:Tds:[server]:[port]/[database]"),
    JTDS("jtds", "net.sourceforge.jtds.jdbc.Driver", "url"),
    POSTGRESQL("postgresql", "org.postgresql.Driver", "url"),
    FAKE("fake", "com.alibaba.druid.mock.MockDriver", "url"),
    MOCK("mock", "com.alibaba.druid.mock.MockDriver", "url"),
    HSQLDB("hsqldb", "org.hsqldb.jdbcDriver", "url"),
    DB2("db2", "COM.ibm.db2.jdbc.app.DB2Driver", "jdbc:db2://[server]:[port]/[database]"),
    SQLITE("sqlite", "org.sqlite.JDBC", "jdbc:sqlite:[database]"),//jdbc:sqlite:D:\\xxxdatabase.db
    INGRES("ingres", "com.ingres.jdbc.IngresDriver", "url"),
    H2("h2", "org.h2.Driver", "jdbc:h2:tcp://[server]/~/[database]"),
    MCKOI("mckoi", "com.mckoi.JDBCDriver", "jdbc:mckoi://[server]/"),
    CLOUDSCAPE("cloudscape", "COM.cloudscape.core.JDBCDriver", "url"),
    INFORMIX("informix", "com.informix.jdbc.IfxDriver", "jdbc:informix-sqli://[server]:[port]/[database]:INFORMIXSERVER=myserver"),
    TIMESTEN("timesten", "com.timesten.jdbc.TimesTenDriver", "url"),
    AS400("as400", "com.ibm.as400.access.AS400JDBCDriver", "jdbc:as400://[server]"),
    SAPDB("sapdb", "com.sap.dbtech.jdbc.DriverSapDB", "jdbc:sapdb://[server]:[port]/[database]"),
    JSQL("jsql", "com.jnetdirect.jsql.JSQLDriver", "url"),
    JTURBO("jturbo", "com.newatlanta.jturbo.driver.Driver", "url"),
    FIREBIRDSQL("firebirdsql", "org.firebirdsql.jdbc.FBDriver", "url"),
    INTERBASE("interbase", "interbase.interclient.Driver", "url"),
    POINTBASE("pointbase", "com.pointbase.jdbc.jdbcUniversalDriver", "url"),
    EDBC("edbc", "ca.edbc.jdbc.EdbcDriver", "url"),
    MIMER("mimer", "com.mimer.jdbc.Driver", "jdbc:mimer:[database]");

    private final String dbType;
    private final String driverCLass;
    private final String url;

    public String getDbType() {
        return dbType;
    }

    public String getDriverCLass() {
        return driverCLass;
    }

    public String getUrl() {
        return url;
    }

    public String getUrl(String server, Integer port, String database) {
        return url.replace("[server]", server).replace("[port]", port.toString()).replace("[database]", database);
    }

    DriverCLassEnum(String dbType, String driverCLass, String url) {
        this.driverCLass = driverCLass;
        this.dbType = dbType;
        this.url = url;
    }

    public static DriverCLassEnum getDBType(String dbType) {
        for (DriverCLassEnum e : DriverCLassEnum.values()) {
            if (e.getDbType().equals(dbType)) {
                return e;
            }
        }
        return null;
    }
}
